package com.skyc.service.impl;

import java.util.List;

import com.mysql.cj.util.Util;
import com.skyc.dao.ClothesDao;
import com.skyc.dao.impl.ClothesDaoImpl;
import com.skyc.entity.Clothes;
import com.skyc.service.ClothesService;

public class ClothesServiceImpl implements ClothesService {
	ClothesDao cdao = new ClothesDaoImpl();

	@Override
	public int kucunqueryByIDSizeColor(String ccid, String size, String color) {
		return cdao.kucunqueryByIDSizeColor(ccid, size, color);
	}

	@Override
	public List<Clothes> listqueryBySalesCcid() {
		return cdao.listqueryBySalesCcid();
	}

	@Override
	public Clothes clothesqueryByCcid(String ccid) {
		return cdao.clothesqueryByCcid(ccid);
	}

	@Override
	public int salesqueryByccid(String ccid) {

		return cdao.salesqueryByccid(ccid);
	}

	@Override
	public List<Clothes> queryTermAll(String sex, String type, String color, String size, String priceMin,
			String priceMax) {
		String aa[] = { sex, type, color, size, priceMin, priceMax };
		queryUtil(aa);
		return cdao.queryTermAll(aa[0], aa[1], aa[2], aa[3], aa[4], aa[5]);
	}

	@Override
	public List<Clothes> queryPriceAsc(String sex, String type, String color, String size, String priceMin,
			String priceMax, String page, String pagesize) {
		String aa[] = { sex, type, color, size, priceMin, priceMax, page, pagesize };
		queryUtil(aa);
		return cdao.queryPriceAsc(aa[0], aa[1], aa[2], aa[3], aa[4], aa[5], aa[6], aa[7]);
	}

	@Override
	public List<Clothes> queryPriceDesc(String sex, String type, String color, String size, String priceMin,
			String priceMax, String page, String pagesize) {
		String aa[] = { sex, type, color, size, priceMin, priceMax, page, pagesize };
		queryUtil(aa);
		return cdao.queryPriceDesc(aa[0], aa[1], aa[2], aa[3], aa[4], aa[5], aa[6], aa[7]);
	}

	@Override
	public List<Clothes> querySalesAsc(String sex, String type, String color, String size, String priceMin,
			String priceMax, String page, String pagesize) {
		String aa[] = { sex, type, color, size, priceMin, priceMax, page, pagesize };
		queryUtil(aa);
		return cdao.querySalesAsc(aa[0], aa[1], aa[2], aa[3], aa[4], aa[5], aa[6], aa[7]);
	}

	@Override
	public List<Clothes> querySalesDesc(String sex, String type, String color, String size, String priceMin,
			String priceMax, String page, String pagesize) {
		String aa[] = { sex, type, color, size, priceMin, priceMax, page, pagesize };
		queryUtil(aa);
		return cdao.querySalesDesc(aa[0], aa[1], aa[2], aa[3], aa[4], aa[5], aa[6], aa[7]);
	}

	private void queryUtil(String aa[]) {
		if (aa[0] == null || "".equals(aa[0])) {
			aa[0] = "%%";
		}else {
			aa[0] = "%"+aa[0].charAt(0)+"%";
		}
		if (aa[1] == null || "".equals(aa[1])) {
			aa[1] = "%%";
		}else {
			aa[1] = "%"+aa[1].charAt(0)+"%";
		}
		if (aa[2] == null || "".equals(aa[2])) {
			aa[2] = "%%";
		}else{
			aa[2] = "%"+aa[2].charAt(0)+"%";
		}
		if (aa[3] == null || "".equals(aa[3])) {
			aa[3] = "%%";
		}
		if (aa[4] == null || "".equals(aa[4])) {
			aa[4] = 0 + "";
		}
		if (aa[5] == null || "".equals(aa[5])) {
			aa[5] = 100000 + "";
		}
		if(aa.length>6){
			if (aa[6] == null || "".equals(aa[6])) {
				aa[6] = "0";
			}
			if (aa[7] == null || "".equals(aa[7])) {
				aa[7] = "25";
			}
		}
		
	}

	@Override
	public int cidqueryByIdSizeColor(String ccid, String size, String color) {
		return cdao.cidqueryByIdSizeColor(ccid, size, color);
	}

	@Override
	public Clothes queryByID(String id) {
		
		return cdao.queryByID(id);
	}

}